<template>
	<view class="home">
		<swiper :indicator-dots="true" :autoplay="true" :interval="13000" :duration="1000">
			<swiper-item v-for="item of swipers" :key="item.id">
				<image :src="item.img" mode=""></image>
			</swiper-item>

		</swiper>

		<view class="nav">
			<view class="nav-item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>

		</view>
		<view class="hot_goods">
			<view class="title">
				推荐商品
			</view>
			<goods-list @itemClick="goGoodsDeatil" :goods="goods"></goods-list>
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		components: {
			goodsList
		},
		data() {
			return {
				swipers: [],
				goods: [],
				navs: [{
						icon: 'iconfont icon-ziyuan',
						title: '商城超市',
						path: '/pages/goods/goods'
					},
					{
						icon: 'iconfont icon-guanyuwomen',
						title: '联系我们',
						path: '/pages/contact/contact'
					},
					{
						icon: 'iconfont icon-tupian',
						title: '社区图片',
						path: '/pages/pics/pics'
					},
					{
						icon: 'iconfont icon-shipin',
						title: '学习视频',
						path: '/pages/videos/videos'
					}
				]
			}
		},
		onLoad() {
			this.getSwipers()
			this.getHotGoods()
		},
		methods: {
			async getSwipers() {
				const res = await this.$myRequest({
					url: '/api/getlunbo',
					method: 'get'
				})
				this.swipers = res.data.message
			},
			async getHotGoods() {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=1'
				})
				this.goods = res.data.message
			},
			navItemClick(url) {
				uni.navigateTo({
					url
				});
			},
			goGoodsDeatil(id){
				uni.navigateTo({
					url:"../good-detail/good-detail?id="+id
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.home {
		swiper {
			width: 750rpx;
			height: 380rpx;

			swiper-item {
				width: 100%;
				height: 100%;

				image {
					width: 100%;
					height: 100%;
				}
			}

		}

		.nav {
			display: flex;

			.nav-item {
				flex: 0 0 25%;
				text-align: center;

				view {
					width: 120rpx;
					height: 120rpx;
					background-color: $uni-main-color;
					border-radius: 50%;
					line-height: 120rpx;
					margin: 10px auto;
					color: #fff;
					font-size: 50rpx;
				}

				text {
					font-size: 28rpx;
				}

				.icon-tupian {
					font-size: 45rpx;
				}
			}
		}

		.hot_goods {
			background-color: #EEEEEE;
			overflow: hidden;
			margin-top: 15px;

			.title {
				height: 100rpx;
				line-height: 100rpx;
				color: $uni-main-color;
				text-align: center;
				letter-spacing: 20px;
				background-color: #FFFfff;
				margin: 7rpx 0;
			}


		}
	}
</style>
